
 // 基础函数：生成二维码 
function qcodetochar(str){  
    var out, i, len, c;  
    out = "";  
    len = str.length;  
    for (i = 0; i < len; i++) {  
        c = str.charCodeAt(i);  
        if ((c >= 0x0001) && (c <= 0x007F)) {  
            out += str.charAt(i);  
        } else if (c > 0x07FF) {  
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));  
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));  
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));  
        } else {  
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));  
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));  
        }  
    }  
    return out;  
};  
$.fn.qcode = function(options){  
    if(options){  
        var opt = {};  
        if(typeof options == 'string'){  
            opt.text = options;  
        }else{  
            if(options.text) opt.text = options.text;  
            if(options.type && options.type == 'ch') opt.text = qcodetochar(opt.text);  
            if(options.render && options.render == 'table') opt.render = options.render;  
            if(options.width) opt.width = options.width;  
            if(options.height) opt.height = options.height;  
        }  
  
        $(this).qrcode(opt);  
    }  
}; 
//基础函数：切换
function setTab(name,cursel,n){
 for(i=1;i<=n;i++){
  var menu=document.getElementById(name+i);
  var con=document.getElementById("con_"+name+"_"+i);
  menu.className=i==cursel?"active":"";
  con.style.display=i==cursel?"block":"none";
 }
}

//数据初始化：模板风格
$.ajax({
  type: "GET",
  url:'/api/v1/category',
  success: function(data) {
    var date = data.result;
    date.forEach(function(e){

      // 模板风格页面：模板分类
      var category_show ='<a category = "'+e.id+'"  class="category_show" id="category_show'+e.id+'">'+e.name+'</a>';
      $("#category_show").append(category_show);
      var model_cont_show = ' <div style="overflow:hidden;" id="model_cont_show'+e.id+'"></div>';
      $("#model_cont_show").append(model_cont_show);

    })

    $(".category_show").on("click",function(){
      var category = $(this).attr("category");
      $(this).siblings().removeClass('active');
      $(this).addClass('active');
      $("#model_cont_show"+category).siblings().css("display","none");
      $("#model_cont_show"+category).show();
    })
    $(".category_show:first").click();

    //数据初始化：模板风格页
    $.ajax({
        type: "GET",
        url:'/api/v1/model',
        success: function(data) {
        var allmodel = data.result;
        for (var i = 0;i<allmodel.length ; i++) {
          var allmodelhtml ='<div class="index-model ">\
                              <img src="'+allmodel[i].img_dir+'">\
                              <a id="makeNow" href="invitation/'+allmodel[i].model_id+'/edit">开始</a>\
                              <div class="code-hid">\
                                <div class="qrcode" demo_id="'+allmodel[i].demo_id+'" id="'+allmodel[i].dir_name+'"></div>\
                                <p>手机扫二维码<br/>即可观看效果</p>\
                              </div>\
                            </div>';
          $("#model_cont_show"+allmodel[i].category_id).append(allmodelhtml);
        }

        $(".model-body-boxes").on("click",function(){
          $(".model-body-boxes").removeClass('active');
          $(this).addClass('active');
        })

        //生成模板的二维码
        $(".qrcode").each(function(){
          var url = 'http://chinalove99.net:83/invitation/'+$(this).attr('demo_id');
          $(this).qcode({  
              text : url,  
              type : 'cn',  
              width : 100,  
              height : 100  
          })
        })
        
        }
    });
  }
})







